package com.lucanjun.cn.springboot.multipledatasources.business.model.vo.base;

import io.swagger.v3.oas.annotations.media.Schema;
import lombok.Data;

import java.io.Serializable;
import java.util.ArrayList;
import java.util.Collections;
import java.util.List;

/**
 * @author lucanjun
 * @version 1.0.0
 * @title PageDto
 * @create 2024-12-19 16:55:19
 * @description 分页数据响应对象
 */
@Data
@Schema(name = "PageVo", description = "分页数据响应对象")
public class PageVo<T> implements Serializable {

    private static final long serialVersionUID = 1338245238758587532L;

    @Schema(description = "数据")
    private List<T> records = Collections.emptyList();
    @Schema(description = "当前页")
    private Long current;
    @Schema(description = "每页显示条数")
    private Long size;
    @Schema(description = "总数据量")
    private Long total;
    @Schema(description = "页面需要展示的页数")
    private Long pages;

    public PageVo() {

    }

    public PageVo(long current, long size, long total, List<T> records) {

        if (records == null) {
            this.current = current;
            this.size = size;
            this.total = total;
            this.records = new ArrayList<>();
            this.pages = 0L;
        } else {
            this.current = current;
            this.size = size;
            this.total = total;
            this.records = records;
            this.pages = (total + size - 1) / size;
        }
    }

}

